#include "tcp_server_test.h"
#include <fcntl.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
  sdx::TcpServer sendfileServer;
  sendfileServer.createSocket();
  sendfileServer.bindIp();
  sendfileServer.listenData();
  sendfileServer.acceptMessage();
  const char *filename = "sendfile_test.txt";
  int filefd = open(filename, O_RDONLY);
  if (filefd == -1) {
    std::cout << "open file failed" << std::endl;
    exit(EXIT_FAILURE);
  }
  struct stat stat_buff;
  fstat(filefd, &stat_buff);
  sendfile(sendfileServer.getAcceptFd(), filefd, NULL, stat_buff.st_size);
  sendfileServer.closeAccept();
  sendfileServer.closeSocket();
  return 0;
}